;(function () {
    // importCss();
    var _global;
    var Content = function (option) {
        var _this = this;
        var defaults = {
            elemId: 'content',
            content: '',
            go_top: '',
            go_bottom: '',
            go_left: '',
            go_right: ''
        };
        this.o = extend(defaults, option);
        console.log(this.o)
        this.containerNode = document.getElementById(this.o.elemId);
        this.containerNode.style.overflow = 'hidden';
        //创建内容节点
        this.contentNode = document.createElement('div');
        this.contentNode.className='content-wrap';
        this.contentNode.style.position = 'relative';
        this.contentNode.innerHTML = this.o.content;
        //将内容节点加入
        this.containerNode.appendChild(this.contentNode);

        this.containerHeight = this.containerNode.clientHeight;
        this.totalHeight = this.contentNode.clientHeight;
        this.totalPage = Math.ceil(this.totalHeight / this.containerHeight);
        this.curPage=1;

        _global.contentPrevBtn_json = {
            go_top: '',
            go_bottom: '',
            go_left: '',
            go_right: 'contentNextBtn'
        };
        _global.contentPrevBtn_onfocus = function (code, id) {
            $('#' + id).addClass('active');
            _global.contentPrevBtn_json.go_top = _this.o.go_top;
            _global.contentNextBtn_json.go_top = _this.o.go_top;
        };
        _global.contentPrevBtn_onblur = function (code, id) {
            $('#' + id).removeClass('active');
        };
        _global.contentPrevBtn_onsubmit = function (code, id) {
            _this.setPage('-')
        };
        _global.contentNextBtn_json = {
            go_top: '',
            go_bottom: '',
            go_left: 'contentPrevBtn',
            go_right: ''
        };
        _global.contentNextBtn_onfocus = function (code, id) {
            $('#' + id).addClass('active')
        };
        _global.contentNextBtn_onblur = function (code, id) {
            $('#' + id).removeClass('active')
        };
        _global.contentNextBtn_onsubmit = function (code, id) {
            _this.setPage('+')
        };

    };

    Content.prototype = {
        addPageControl: function (left,top) {
            var html = '<div id="contentPrevBtn" class="prev-container"><span class="prev-btn">上一页</span></div>' +
                '<div class="page-info"><span>1/1</span></div>' +
                '<div id="contentNextBtn" class="next-container"><span class="next-btn">下一页</span></div>';

            this.pageControlNode = document.createElement('div');
            this.pageControlNode.className = 'page-control';
            this.pageControlNode.innerHTML = html;
            this.containerNode.parentNode.appendChild(this.pageControlNode);

            this.pageControlNode.style.position='absolute';
            if(left && top){
                this.pageControlNode.style.left=left+'px';
                this.pageControlNode.style.top=top+'px';
            }
            this.setPage(this.curPage);
            return this;
        },
        /**
         * 设置显示页数
         * @param page
         */
        setPage: function (page) {
            switch (page) {
                case '+':
                    if (this.curPage < this.totalPage) {
                        this.curPage++;
                        console.log('++++++')
                    }
                    break;
                case '-':
                    if (this.curPage > 1) {
                        this.curPage--;
                        console.log('------')
                    }
                    break;
                default:
                    this.curPage = page;
                    break;
            }
            // console.log(this.pageControlNode);
            this.pageControlNode.querySelector('.page-info span').innerText=this.curPage+'/'+this.totalPage;
            this.contentNode.style.top=-(this.curPage-1)*this.containerHeight+'px';
        },
        prevPage: function () {
            this.setPage('-');
        },
        nextPage: function () {
            this.setPage('+');
        }
    };

    function initFocus() {

    }

    function importCss() {
        var head = document.getElementsByTagName("head");
        var css = document.createElement("link");
        css.href = '../css/plug-in/dialog.css';
        css.rel = "stylesheet";
        css.type = "text/css";
        head[0].appendChild(css);
    }

    function extend(target, options, deep) {
        for (var key in options) {
            if (options.hasOwnProperty(key)) {
                var copy = options[key];
                if (deep && copy instanceof Array) {
                    target[key] = extend(target[key], copy, deep);
                } else if (deep && copy instanceof Object) {
                    target[key] = extend(target[key], copy, deep);
                } else {
                    target[key] = options[key];
                }
            }
        }
        return target;
    }

    _global = (function () {
        return this || (0, eval)('this');
    }());
    //导出为通用规范模块
    if (typeof module !== "undefined" && module.exports) {
        module.exports = Content;
    } else if (typeof define === "function" && define.amd) {
        define(function () {
            return Content;
        });
    } else {
        !('Content' in _global) && (_global.Content = Content);
    }
})();